#ifndef SCREENCAMERAN_H
#define SCREENCAMERAN_H
#include <QThread>
#include "IndustryCamera.h"

class QScreen;


class ScreenCamera;

/**
 * @brief The ScreenCameraInfo class 查询屏幕相机的信息的类
 * 用这个类可以查到当前计算机接了几个显示器，给出每个显示器的名称（deviceName）
 */
class ScreenCameraInfo
{
    friend class ScreenCamera;
public:
    explicit ScreenCameraInfo(QScreen * screen = nullptr);
    ScreenCameraInfo(const ScreenCameraInfo &info);
    /**
     * @brief description 没有实现，返回空字符串
     * @return 返回空字符串。
     */
    QString description() const;
    /**
     * @brief deviceName 给出屏幕的名称，比如 "\\\\.\\DISPLAY1", "VGA1" 一类的名称。
     * @return
     */
    QString deviceName() const;
    bool isNull() const;
    bool operator!=(const ScreenCameraInfo &other) const;
    ScreenCameraInfo &operator=(const ScreenCameraInfo &other);
    bool operator==(const ScreenCameraInfo &other) const;

    static QList<ScreenCameraInfo> availableCameras();
    static ScreenCameraInfo defaultCamera();

private:
    QScreen* m_screen;
};

class ScreenCamera: public IndustryCamera, public QThread
{
public:
    ScreenCamera(QObject *parent = nullptr);
    /**
     * @brief setROI 设置感兴趣的区域，利用这个函数我们可以只截取屏幕的一部分区域
     * @param x 截屏区域的起始X坐标
     * @param y 截屏区域的起始Y坐标
     * @param width 截屏区域的宽度，-1 表示完整的屏幕宽度
     * @param height 截屏区域的高度，-1 表示完整的屏幕高度
     */
    bool setROI(int x, int y, int width, int height);

    bool setROI(QRect rect) Q_DECL_OVERRIDE;
    /**
     * @brief capture 获取截屏图像
     * @return
     */
    QImage capture();
public slots:

    bool isLive() Q_DECL_OVERRIDE {return isRunning();}
    bool openDefaultCamera() Q_DECL_OVERRIDE;
    bool startGrabbing() Q_DECL_OVERRIDE;
    bool stopGrabbing() Q_DECL_OVERRIDE;
    bool setPixelType(PixelType type) Q_DECL_OVERRIDE {Q_UNUSED(type); return true;}
    bool saveSettingsToFile(QString fileName) Q_DECL_OVERRIDE{Q_UNUSED(fileName); return true;}
    bool loadSettingsFromFile(QString fileName) Q_DECL_OVERRIDE{Q_UNUSED(fileName); return true;}
    void close() Q_DECL_OVERRIDE {}

    bool setAutoBrightness(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setAutoWhiteBalance(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setAutoGain(bool on)  Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setAutoExpoureTime(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}

    bool setBrightness(int value) Q_DECL_OVERRIDE {Q_UNUSED(value); return true;}
    bool brightness(int &nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}

    bool setExpoureTime(double us) Q_DECL_OVERRIDE {Q_UNUSED(us); return true;}
    bool expoureTime(double &us) Q_DECL_OVERRIDE {Q_UNUSED(us); return true;}

    bool setWhiteBalance(int red, int green, int blue) Q_DECL_OVERRIDE {Q_UNUSED(red); Q_UNUSED(green); Q_UNUSED(blue); return true;}
    bool whiteBalance(int &red, int &green, int &blue) Q_DECL_OVERRIDE {Q_UNUSED(red); Q_UNUSED(green); Q_UNUSED(blue); return true;}

    bool setGamma(double v) Q_DECL_OVERRIDE {Q_UNUSED(v); return true;}
    bool gamma(double &v) Q_DECL_OVERRIDE {Q_UNUSED(v); return true;}
    bool gammaEnable(bool &on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setGammaEnable(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}

    bool setGain(double fValue) Q_DECL_OVERRIDE {Q_UNUSED(fValue); return true;}
    bool gain(double &fValue) Q_DECL_OVERRIDE {Q_UNUSED(fValue); return true;}

    bool showVCDPropertyPage() Q_DECL_OVERRIDE { return true;}

    bool frameRate(double &fps) Q_DECL_OVERRIDE {Q_UNUSED(fps); return true;}
    bool setFrameRate(double fps) Q_DECL_OVERRIDE;

    bool setSharpness(int nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool sharpness(int &nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool sharpnessEnable(bool &on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setSharpnessEnable(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}

    bool setBlackLevel(int nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool blackLevel(int &nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}

    bool setContrast(int nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool contrast(int &nValue)  Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}

    bool setSaturation(int nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool saturation(int &nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool setSaturationEnable(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool saturationEnable(bool &on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}

    bool setDenoise(int nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool denoise(int &nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool denoiseEnable(bool &on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setDenoiseEnable(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}

    bool setHue(int nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool hue(int &nValue) Q_DECL_OVERRIDE {Q_UNUSED(nValue); return true;}
    bool hueEnable(bool &on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}
    bool setHueEnable(bool on) Q_DECL_OVERRIDE {Q_UNUSED(on); return true;}

private:
    void run() Q_DECL_OVERRIDE;

    int m_sleepInterval;
    QScreen* m_screen;
    int m_x;
    int m_y;
    int m_width;
    int m_height;
};

#endif // SCREENCAMERAN_H
